/*
 * TestDumpOutputStream.c
 *
 *  Created on: 2012/05/30
 *      Author: guanxiaoying
 */
#include "TestDump.h"

static HFILE hFile = FILE_HANDLE_NULL;

VOID dumpOutputStream( PSZ str ){
	S4 res;
	if( str_length(str) > 0 ){
		if( hFile == FILE_HANDLE_NULL ){
			printf( str );
		}else{
			res = FileWrite(hFile, str, strlen(str) );
			if( res != COEXIT_SUCCESS )
			{
				printf( str );
				memset( file_buf, 0, sizeof( file_buf ));
				FileGetFullPath( hFile, file_buf, OS_FULLPATH );
				printf( "Output stream error:%s", file_buf );
				hFile = FILE_HANDLE_NULL;
				FileClose(hFile);
			}
		}
	}
}
VOID dumpParameterStr( PSZ str ){
	CHAR temp[10]="\0\0";
	if( str != NULL ){
		while( *str != '\0' ){
			dumpXMLConvert(*str, temp );
			dumpOutputStream( temp );
			str++;
		}
	}
}
S4 dumpOutputStreamInit_file( PSZ pszPath ){

	if( pszPath == NULL || hFile != FILE_HANDLE_NULL ){
		return COEXIT_FATAL;
	}
	if( COEXIT_SUCCESS != FileOpen( pszPath, FLMOD_WRITEONLY, &hFile )){
		FileClose(hFile);
		hFile = FILE_HANDLE_NULL;
		return COEXIT_FATAL;
	}
	return COEXIT_SUCCESS;
}
VOID dumpOutputStreamEnd_file( VOID ){

	if( hFile != FILE_HANDLE_NULL ){
		FileClose(hFile);
		hFile = FILE_HANDLE_NULL;
	}
}
